//index.js
//获取应用实例
const app = getApp()
var video = null
let touchDotX = 0; //X按下时坐标
let touchDotY = 0; //y按下时坐标
Page({
  data: {
    motto: 'Hello World',
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    p1: true,
    p2: true,
    p3: false,
    p4: true,
    p5: true,
    current: 1,
    imgUrls: [
      "https://s2.ax1x.com/2019/02/12/kds2WQ.png",
      "https://s2.ax1x.com/2019/02/12/kdsgJg.png",
      "https://s2.ax1x.com/2019/02/12/kdsyo8.png",
      "https://s2.ax1x.com/2019/02/12/kdssdf.png",
      "https://s2.ax1x.com/2019/02/12/kdsreP.png",
      "https://s2.ax1x.com/2019/02/12/kdsBLt.png",
      "https://s2.ax1x.com/2019/02/12/kds0sI.png",
      "https://s2.ax1x.com/2019/02/12/kdswQA.png",
      "https://s2.ax1x.com/2019/02/12/kdsazd.png",
      "https://s2.ax1x.com/2019/02/12/kdsURH.png",
      "https://s2.ax1x.com/2019/02/12/kdsNJe.png",
      "https://s2.ax1x.com/2019/02/12/kdstiD.png",
      "https://s2.ax1x.com/2019/02/12/kdsJIO.png"
    ],
  },
  onLoad: function() {
  
  },

  goToSecond() {
    // wx.navigateTo({
    //   url: '../second/second',
    // })
    this.setData({
      p1: true,
      p2: false,
      p3: true,
      p4: true,
      p5: true,
      current: 2
    })

  },

  goToFirst() {
    this.setData({
      p1: false,
      p2: true,
      p3: true,
      p4: true,
      p5: true,
      current: 1
    })
  },

  goToThird() {
    this.setData({
      p1: true,
      p2: true,
      p3: false,
      p4: true,
      p5: true,
      current: 3
    })
  },

  goToSecondFromP3() {
    this.setData({
      p1: true,
      p2: false,
      p3: true,
      p4: true,
      p5: true,
      current: 2
    })
  },

  goToFourth() {
    this.setData({
      p1: true,
      p2: true,
      p3: true,
      p4: false,
      p5: true,
      current: 4
    })
  },

  goToThirdFromP4() {
    this.setData({
      p1: true,
      p2: true,
      p3: false,
      p4: true,
      p5: true,
      current: 3
    })
    // video.pause()
  },

  goToFifth() {
    this.setData({
      p1: true,
      p2: true,
      p3: true,
      p4: true,
      p5: false,
      current: 5
    })
    // video.pause()
  },

  goToFourthFromP5() {
    this.setData({
      p1: true,
      p2: true,
      p3: true,
      p4: false,
      p5: true,
      current: 4
    })
  },

  saveImage() {
    wx.showModal({
      title: '保存',
      content: '是否保存到相册？',
      confirmText: '保存',
      cancelText: '取消',
      success: function(res) {
        if (res.confirm) {
          wx.saveImageToPhotosAlbum({
            filePath: '/pages/image/微信图片_20180611102952.jpg',
            success: function(res) {
              console.log(res)
              wx.showToast({
                title: '保存成功',
              })
            },
            complete: function(res) {
              console.log(res)
            }
          })
        } else {
          //取消
        }
      }
    })
  },

  toCall() {
    wx.showModal({
      title: '温馨提醒',
      content: '是否拨打手机？',
      success: function(res) {
        if (res.confirm) {
          wx.makePhoneCall({
            phoneNumber: '17858762725',
          })
        } else {
          //取消
        }
      }
    })
  },

  copy(e) {
    var num = e.currentTarget.dataset.num;
    var id = e.currentTarget.dataset.id;
    wx.showModal({
      title: '温馨提示',
      content: '是否复制' + id + '到剪贴板？',
      success: function(res) {
        if (res.confirm) {
          wx.setClipboardData({
            data: num,
            success: function(res) {
              console.log(res)
              wx.showToast({
                title: '已复制',
              })
            }
          })
        }
      }
    })
  },

  onShow() {
    video = wx.createVideoContext('video', this);
  },

  // 触摸开始事件
  touchStart: function(e) {
    touchDotX = e.touches[0].pageX; // 获取触摸时的原点
    touchDotY = e.touches[0].pageY;
  },
  // 触摸结束事件
  touchEnd: function(e) {
    var that = this;
    let touchMoveX = e.changedTouches[0].pageX;
    let touchMoveY = e.changedTouches[0].pageY;
    let tmX = touchMoveX - touchDotX;
    let tmY = touchMoveY - touchDotY;
    // if (time < 20) {
    let absX = Math.abs(tmX);
    let absY = Math.abs(tmY);
    if (absX > 2 * absY) {
      if (tmX < 0) {
        console.log("左滑=====")
        if(that.data.current == 1){
          that.goToSecond()
          that.setData({
            current: 2
          })
        }else if(that.data.current == 2){
          that.goToThird()
          that.setData({
            current: 3
          })
        }else if(that.data.current == 3){
          that.goToFourth()
          that.setData({
            current: 4
          })
        }else{
          that.goToFifth()
          that.setData({
            current: 5
          })
        }
      } else {
        console.log("右滑=====")
        if(that.data.current == 2){
          that.goToFirst()
          that.setData({
            current: 1
          })
        }else if(that.data.current == 3){
          that.goToSecondFromP3()
          that.setData({
            current: 2
          })
        }else if(that.data.current == 4){
          that.goToThirdFromP4()
          that.setData({
            current: 3
          })
        }else if(that.data.current == 5){
          that.goToFourthFromP5()
          that.setData({
            current: 4
          })
        }
      }
    }
    // }
  }
})